#include"qtreewidget_ex.h"
#include"qlistwidget_ex.h"
#include<QDebug>
#include<QMimeData>
#include<QDragEnterEvent>
#include<QDragMoveEvent>
#include<QDropEvent>
QtreeWidget_Ex::QtreeWidget_Ex(){}
void QtreeWidget_Ex::dragEnterEvent (QDragEnterEvent *e)
{
    QListWidget_Ex* source=qobject_cast<QListWidget_Ex*>(e->source ());
    if(source)
    {
        e->setDropAction (Qt::MoveAction);
        e->accept ();
    }
}

void QtreeWidget_Ex::dragMoveEvent (QDragMoveEvent *e)
{
    QListWidget_Ex* source=qobject_cast<QListWidget_Ex*>(e->source ());
    if(source)
    {
        e->setDropAction (Qt::MoveAction);
        e->accept ();
    }
}
void QtreeWidget_Ex::dropEvent (QDropEvent *e)
{
    QListWidget_Ex* source=qobject_cast<QListWidget_Ex*>(e->source ());
    if(source)
    {
       QModelIndex currentIdx=indexAt (e->pos ());
       if(currentIdx.isValid ())
       {
           QTreeWidgetItem* item=itemFromIndex (currentIdx);
           model ()->insertRow (item->childCount (),currentIdx);
           QModelIndex childIdx=model()->index (item->childCount ()-1,0,currentIdx);
           model()->setData (childIdx,QVariant(e->mimeData ()->text()),Qt::DisplayRole);
           e->setDropAction (Qt::MoveAction);
           e->accept ();
       }
    }
}
